package cn.edu.cqupt.cxcy.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cqupt.cxcy.dto.TeamImpl;
import cn.edu.cqupt.cxcy.model.Team;

/**
 * Servlet implementation class TeamInfoIndex
 */
@WebServlet("/TeamInfoIndex")
public class TeamInfoIndex extends HttpServlet {
	private static final long serialVersionUID = 1L;
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pjax_back = "$(function(){$(\"a.pjax[href='index_team']\").trigger('click');});";
		if(request.getHeader("x-pjax") == null || request.getHeader("x-pjax").equals("null")) {
			request.setAttribute("pjax_back", pjax_back);
			request.getRequestDispatcher( "html/index.jsp").forward(request, response);
			return;
		} else{
		int teamId = Integer.valueOf(request.getParameter("id"));
		TeamImpl teamImpl = new TeamImpl();
		Team team = teamImpl.teamInfo(teamId);
		request.setAttribute("teaminfo", team);
		request.getRequestDispatcher("html/team_fy.jsp").forward(request, response);
		}
	}

}
